package logic

import (
	"context"
	"gorm.io/gorm"
	"usershop/user_srv/model/mysql"

	"usershop/user_srv/internal/svc"
	"usershop/user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type RegisterUserLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRegisterUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterUserLogic {
	return &RegisterUserLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *RegisterUserLogic) RegisterUser(in *user.ResisterUserRequest) (*user.CreateUserResponse, error) {
	// todo: 用户注册
	u := mysql.User{
		Model:    gorm.Model{},
		Username: in.Username,
		Password: in.Password,
		Sale:     in.Sale,
		Mobile:   in.Tel,
	}
	err := u.Reg() //注册
	if err != nil {
		logx.Error("新增失败", err)
		return nil, err
	}

	return &user.CreateUserResponse{}, nil
}
